<?php
declare (strict_types=1);

namespace app\api\controller\v2;

use app\common\model\Website;
use app\common\model\Nav as NavModel;


class Nav
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //
        return sucessMsg('200', '获取成功', [
            'topnav' => $this->topnav(), //获取顶部导航
            'butnav' => $this->butnav(),//获取底部导航
            'website' => $this->website(),//获取底部网站信息
        ]);
    }

    /**
     *
     *获取顶部导航
     */
    public function topnav()
    {
        return NavModel::where(['type' => 1, 'status' => 1])
            ->field('id,name,image')
            ->order('sort', 'asc')
            ->withAttr('image', function ($val, $data) {
                return env('app.yuming') . $val;
            })
            ->select();
    }


    /**
     * 获取底部导航
     */
    public function butnav()
    {
        return NavModel::where(['type' => 2, 'status' => 1])
            ->field('id,name,image')
            ->order('sort', 'asc')
            ->withAttr('image', function ($val, $data) {
                return env('app.yuming') . $val;
            })
            ->select();
    }

    public function website()
    {
        return Website::field('*')
            ->order('id', 'desc')
            ->withAttr('logo', function ($val, $data) {
                return env('app.yuming') . $val;
            })
            ->withAttr('wCode', function ($val1, $data) {
                return env('app.yuming') . $val1;
            })
            ->select();
    }

}
